#!/usr/local/bin/python3
# -*- coding: UTF-8 -*-
"""
@author:apple
@file:PriorityQueue.py
@time:2021/07/26
"""
import heapq


class PriorityQueue:
    ...

    def __init__(self):
        self._container = []
        self._index = 0

    def push(self, val, priority):
        ...
        """
        越小的值排在前面，所以要使用 -priority
        """
        heapq.heappush(self._container, (-priority, self._index, val))
        self._index += 1

    def pop(self):
        return heapq.heappop(self._container)[-1]

    def peek(self):
        return self._container[0][-1]

    def empty(self):
        return len(self._container) == 0




if __name__ == '__main__':
    pass
    pQueue = PriorityQueue()
    pQueue.push(1,23)
    pQueue.push(2,12)
    pQueue.push(3,20)
    pQueue.push(5,12)
    while not pQueue.empty():
        print(pQueue.pop())